const {defineConfig} = require('@vue/cli-service')
const path = require('path');
require('events').EventEmitter.defaultMaxListeners = 0

function resolve(dir) {
  return path.join(__dirname, dir)
}

let baseUrl = process.env.NODE_ENV === 'production' ?
  "https://lexiang.langzhiyun.net" : 'https://lexiang.langzhiyun.net'

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true
    }
  },

// 区分打包环境与开发环境
// process.env.NODE_ENV==='production'  // (打包环境)
// process.env.NODE_ENV==='development' // (开发环境)
// baseUrl: process.env.NODE_ENV==='production'?"https://cdn.didabisai.com/front/":'front/',
  devServer: {
    proxy: {
      '/security': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/security': '/security'
        }
      },
      '/bms': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/bms': '/bms'
        }
      },
      '/pms': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/pms': '/pms'
        }
      },
      '/lms': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/lms': '/lms'
        }
      },
      '/iot': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/iot': '/iot'
        }
      },
      '/interface': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/interface': '/interface'
        }
      },
      '/interfaces': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/interfaces': '/interfaces'
        }
      },
      '/cms': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/cms': '/cms'
        }
      },
      '/rms': {
        target: baseUrl,
        ws: true,
        changeOrigin: true,//允许跨域
        pathRewrite: {
          '^/rms': '/rms'
        }
      }
    }
  },
//  将接收 ChainableConfig由webpack-chain提供支持的实例的函数。
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('style', resolve('src/assets/style'))
      .set('script', resolve('src/assets/script'))
      .set('@img', resolve('src/assets/images'))
      .set('com', resolve('src/components'))
      .set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js')
  }
})
